//
//  SystemViewModel.swift
//  ezyform
//
//  Created by MoennigQ on 16/10/20.
//  Copyright © 2020 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import Alamofire
enum ErrorType: Int{
    case PanelInstalled = 1
    case Checklist = 2
    case FinishJob = 3
    case PanelNumber = 4
    case InverterNumber = 5
    case Signature = 6
}
class SystemViewModel: BaseService {
    //发送错误日志到Web，此API还未发布到生产环境
    func sendErrorLog(_ msg: String,type: ErrorType){
        
        let params: Parameters = ["id": JobDetailModelHelper.shared.jobDetailModel.id,
                                  "error_message" : msg,
                                  "type": type.rawValue]
        
        let url : String = APIConfig.getRequestAPIForV2(APIConfig.ErrorLogAPI)
        
        let alRequest = ALRequest.init(mainURL: url, method: .put, headers: RequestConstant.AuthTokenParam, paramDict: params, successBlock: { (obj, _) -> Void in
            
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
    //获取job所有的error histories
    func getErrorHistories(){
        
        let params: Parameters = ["pvd_id": JobDetailModelHelper.shared.jobDetailModel.id]
        
        let url : String = APIConfig.getRequestAPIForV2(APIConfig.ErrorHistoriesAPI)
        
        let alRequest = ALRequest.init(mainURL: url, method: .get, headers: RequestConstant.AuthTokenParam, paramDict: params, successBlock: { (obj, _) -> Void in
            self.returnBlock(obj, nil)
        }){(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
    //获取jobs是否有not read
    func getErrorNotRead(){
        
        let params: Parameters = ["ids": JobDetailModelHelper.shared.jobDetailModel.id]
        
        let url : String = APIConfig.getRequestAPIForV2(APIConfig.ErrorNotReadAPI)
        
        let alRequest = ALRequest.init(mainURL: url, method: .get, headers: RequestConstant.AuthTokenParam, paramDict: params, successBlock: { (obj, _) -> Void in
            
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
}
